// Check if all required environment variables are set
require('dotenv').config();
const path = require('path');

console.log('Environment Check:');
console.log('==================');

// Define required environment variables
const requiredVars = [
  { name: 'JWT_SECRET', description: 'Secret key for JWT token generation' },
  { name: 'DB_HOST', description: 'Database host', default: 'localhost' },
  { name: 'DB_USER', description: 'Database user', default: 'root' },
  { name: 'DB_PASSWORD', description: 'Database password', default: 'root' },
  { name: 'DB_NAME', description: 'Database name', default: 'pet_adoption' },
  { name: 'PORT', description: 'Server port', default: '3000' }
];

// Path to .env file
const envPath = path.join(__dirname, '.env');
const fs = require('fs');
const envFileExists = fs.existsSync(envPath);

console.log(`Checking for .env file at: ${envPath}`);
console.log(`.env file exists: ${envFileExists ? 'Yes' : 'No'}`);
console.log('');

let missingVars = [];

// Check each required variable
requiredVars.forEach(variable => {
  const value = process.env[variable.name];
  const isSet = !!value;
  const status = isSet ? '✅ Set' : (variable.default ? '⚠️ Using default' : '❌ Missing');
  
  console.log(`${variable.name}: ${status}`);
  console.log(`  Description: ${variable.description}`);
  if (!isSet && variable.default) {
    console.log(`  Default value will be used: ${variable.default}`);
  }
  console.log('');
  
  if (!isSet && !variable.default) {
    missingVars.push(variable.name);
  }
});

// Summary
if (missingVars.length > 0) {
  console.log('❌ MISSING REQUIRED VARIABLES:');
  missingVars.forEach(varName => {
    console.log(`  - ${varName}`);
  });
  console.log('\nPlease add these variables to your .env file to ensure proper application function.');
  
  // Create sample .env file content
  let sampleEnvContent = '# Sample .env file\n';
  requiredVars.forEach(variable => {
    const value = variable.name === 'JWT_SECRET' ? 
      'your_secret_key_here' : 
      (process.env[variable.name] || variable.default || 'your_value_here');
    sampleEnvContent += `${variable.name}=${value}\n`;
  });
  
  console.log('\nSample .env file:');
  console.log('---------------');
  console.log(sampleEnvContent);
} else {
  console.log('✅ All required environment variables are set!');
} 